<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var intervalIntersection = function (firstList, secondList) {
      let i = 0, j = 0, ans = [], A = firstList, B = secondList;
      while (i < A.length && j < B.length) {
        //左边取大的一个
        let left = Math.max(A[i][0], B[j][0]),
          //右边取小的一个
          right = Math.min(A[i][1], B[j][1]);
        if (left <= right) ans.push([left, right])
        A[i][1] > B[j][1] ? j++ : i++
      }
      return ans
    };
    console.log(intervalIntersection(firstList = [[0, 2], [5, 10], [13, 23], [24, 25]], secondList =
      [[1, 5], [8, 12], [15, 24], [25, 26]]
    ))
  </script>
</body>

</html>